package com.common.context.listener;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContext;

import org.springframework.web.context.support.WebApplicationContextUtils;
import org.springframework.context.ApplicationContext;

import com.common.context.ApplicationContextUtil;


public class ContextLoaderListener extends org.springframework.web.context.ContextLoaderListener {

    public void contextInitialized(ServletContextEvent event) {
        super.contextInitialized(event);

        // context
        ServletContext context = event.getServletContext();
        ApplicationContext ctx = WebApplicationContextUtils.getRequiredWebApplicationContext(context);
        ApplicationContextUtil.setApplicationContext(ctx);

        // app real path
        String appRealPath = event.getServletContext().getRealPath("/");
        ApplicationContextUtil.setAppRealPath(appRealPath);

    }
}
